

#include "stdafx.h"

BOOL RegWriteDWord(HKEY mkey, LPCWSTR subkey, LPCWSTR keyname, DWORD value){
	
	HKEY hkey;
	BOOL result = FALSE;
	DWORD dwDisposition = REG_OPENED_EXISTING_KEY;

	LSTATUS lrt = RegCreateKeyEx(mkey, subkey, NULL, NULL,
		REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisposition);

	if(ERROR_SUCCESS == lrt){
		if( RegSetValueEx(hkey, _T("Port"), NULL, REG_DWORD, 
			(BYTE *)&value, sizeof(DWORD)) == ERROR_SUCCESS){
			result = TRUE;
		}
	}

	RegCloseKey(hkey); 
	return result;
}


BOOL RegReadDWord(HKEY mkey, LPCWSTR subkey, LPCWSTR keyname, DWORD *value){
    HKEY hkey;
	BOOL result = FALSE;

    LSTATUS lret = RegOpenKeyEx(mkey, subkey, 0, KEY_ALL_ACCESS , &hkey);
	if(ERROR_SUCCESS == lret){
		DWORD size = sizeof(DWORD);
		if(ERROR_SUCCESS == RegQueryValueEx(hkey,keyname,NULL, NULL,(BYTE *)value, &size)){
			result = TRUE;
		}
	}
	RegCloseKey(hkey); 

	return result;
}